home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / window2a / clswinvi.cls < prev    next >
Text File  |  1999-09-06  |  20KB  |  531 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsWinView"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  17. Option Explicit
  18.  
  19. ' Name:     Windows Information Viewer
  20. ' Author:   Chong Long Choo
  21. ' Date:     06 September 1999
  22.  
  23. ' API type definitions
  24.  
  25. Private Type POINTAPI
  26.     x As Long
  27.     y As Long
  28. End Type
  29.  
  30. Private Type RECT
  31.     Left As Long
  32.     Top As Long
  33.     Right As Long
  34.     Bottom As Long
  35. End Type
  36.  
  37. ' Window field offsets for GetWindowLong() and GetWindowWord()
  38.  
  39. Const GWL_WNDPROC = (-4)
  40. Const GWL_HINSTANCE = (-6)
  41. Const GWL_HWNDPARENT = (-8)
  42. Const GWL_STYLE = (-16)
  43. Const GWL_EXSTYLE = (-20)
  44. Const GWL_USERDATA = (-21)
  45. Const GWL_ID = (-12)
  46.  
  47. ' Class field offsets for GetClassLong() and GetClassWord()
  48.  
  49. Const GCL_MENUNAME = (-8)
  50. Const GCL_HBRBACKGROUND = (-10)
  51. Const GCL_HCURSOR = (-12)
  52. Const GCL_HICON = (-14)
  53. Const GCL_HMODULE = (-16)
  54. Const GCL_CBWNDEXTRA = (-18)
  55. Const GCL_CBCLSEXTRA = (-20)
  56. Const GCL_WNDPROC = (-24)
  57. Const GCL_STYLE = (-26)
  58. Const GCW_ATOM = (-32)
  59.  
  60. ' Window Styles
  61.  
  62. Const WS_OVERLAPPED = &H0&
  63. Const WS_POPUP = &H80000000
  64. Const WS_CHILD = &H40000000
  65. Const WS_MINIMIZE = &H20000000
  66. Const WS_VISIBLE = &H10000000
  67. Const WS_DISABLED = &H8000000
  68. Const WS_CLIPSIBLINGS = &H4000000
  69. Const WS_CLIPCHILDREN = &H2000000
  70. Const WS_MAXIMIZE = &H1000000
  71. Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
  72. Const WS_BORDER = &H800000
  73. Const WS_DLGFRAME = &H400000
  74. Const WS_VSCROLL = &H200000
  75. Const WS_HSCROLL = &H100000
  76. Const WS_SYSMENU = &H80000
  77. Const WS_THICKFRAME = &H40000
  78. Const WS_GROUP = &H20000
  79. Const WS_TABSTOP = &H10000
  80. Const WS_MINIMIZEBOX = &H20000
  81. Const WS_MAXIMIZEBOX = &H10000
  82.  
  83. ' Thank to Steve McMahon because provide me all the
  84. ' constant of Extended Window Styles.
  85. ' Extended Window Styles
  86. ' NT3.5x
  87. Private Const WS_EX_DLGMODALFRAME = &H1&
  88. Private Const WS_EX_NOPARENTNOTIFY = &H4&
  89. Private Const WS_EX_TOPMOST = &H8&
  90. Private Const WS_EX_ACCEPTFILES = &H10&
  91. Private Const WS_EX_TRANSPARENT = &H20&
  92.  
  93. ' Win9x/NT4
  94. Private Const WS_EX_MDICHILD = &H40&
  95. Private Const WS_EX_TOOLWINDOW = &H80&
  96. Private Const WS_EX_WINDOWEDGE = &H100&
  97. Private Const WS_EX_CLIENTEDGE = &H200&
  98. Private Const WS_EX_CONTEXTHELP = &H400&
  99.  
  100. Private Const WS_EX_RIGHT = &H1000&
  101. Private Const WS_EX_LEFT = &H0&
  102. Private Const WS_EX_RTLREADING = &H2000&
  103. Private Const WS_EX_LTRREADING = &H0&
  104. Private Const WS_EX_LEFTSCROLLBAR = &H4000&
  105. Private Const WS_EX_RIGHTSCROLLBAR = &H0&
  106.  
  107. Private Const WS_EX_CONTROLPARENT = &H10000
  108. Private Const WS_EX_STATICEDGE = &H20000
  109. Private Const WS_EX_APPWINDOW = &H40000
  110.  
  111. Private Const WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE Or WS_EX_CLIENTEDGE)
  112. Private Const WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST)
  113.  
  114. ' Win2000
  115. Private Const WS_EX_LAYERED = &H80000
  116. Private Const WS_EX_NOINHERITLAYOUT = &H100000      '// Disable inheritence of mirroring by children
  117. Private Const WS_EX_LAYOUTRTL = &H400000            '// Right to left mirroring
  118. Private Const WS_EX_NOACTIVATE = &H8000000
  119.  
  120. ' Class styles
  121. Const CS_VREDRAW = &H1
  122. Const CS_HREDRAW = &H2
  123. Const CS_KEYCVTWINDOW = &H4
  124. Const CS_DBLCLKS = &H8
  125. Const CS_OWNDC = &H20
  126. Const CS_CLASSDC = &H40
  127. Const CS_PARENTDC = &H80
  128. Const CS_NOKEYCVT = &H100
  129. Const CS_NOCLOSE = &H200
  130. Const CS_SAVEBITS = &H800
  131. Const CS_BYTEALIGNCLIENT = &H1000
  132. Const CS_BYTEALIGNWINDOW = &H2000
  133. Const CS_PUBLICCLASS = &H4000
  134.  
  135. Const GW_HWNDNEXT = 2
  136. Const GW_OWNER = 4
  137. Const GW_CHILD = 5
  138. Const GW_MAX = 5
  139.  
  140. Const WM_USER = &H400
  141.  
  142. ' API Functions
  143. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
  144. Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
  145. Private Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
  146. Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
  147. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  148. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  149. Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
  150. Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  151. Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam&) As Long
  152. Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
  153. Private Declare Function GetCapture Lib "user32" () As Long
  154. Private Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  155. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  156. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  157. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  158. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  159. Private Declare Function ReleaseCapture Lib "user32" () As Long
  160. Private Declare Function SendMessageLongByRef Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, lParam As Long) As Long
  161. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
  162. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
  163. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  164. Private Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  165. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  166. Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  167. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  168. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
  169. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  170.  
  171. ' Build a list of all top level windows.
  172. Public Sub ListTopLevelWindow()
  173.     Dim hwnd As Long
  174.     Dim res As Long
  175.     Set objListTop = New clsWinView
  176.     res = EnumWindows(AddressOf CallBack_EnumWindows, 0&)
  177.     Set objListTop = Nothing
  178. End Sub
  179.  
  180. '   Show the position of the selected window
  181. Public Sub GetPosition(hwnd As Long, WinPosition As clsWinPosition, Optional strWindow As String)
  182.     Dim WindowRect As RECT
  183.     Dim useHwnd As Long
  184.     Dim objTmpWinPos As clsWinPosition
  185.     Set objTmpWinPos = New clsWinPosition
  186.     If hwnd Then
  187.         useHwnd = hwnd
  188.     Else
  189.         useHwnd = GetHwndFromWord(strWindow)
  190.     End If
  191.     ' Get the rectangle describing the window
  192.     GetWindowRect useHwnd, WindowRect
  193.     With objTmpWinPos
  194.         .Is_Iconic = (IsIconic(useHwnd))
  195.         .Is_Zoomed = (IsZoomed(useHwnd))
  196.         .Is_Enabled = (IsWindowEnabled(useHwnd))
  197.         .Is_Visible = (IsWindowVisible(useHwnd))
  198.         .Left = WindowRect.Left
  199.         .Top = WindowRect.Top
  200.         .Right = WindowRect.Right
  201.         .Bottom = WindowRect.Bottom
  202.     End With
  203.     Set WinPosition = objTmpWinPos
  204. End Sub
  205.  
  206. '   Show the size of the selected window
  207. Public Sub GetSize(hwnd As Long, WinSize As clsWinSize, Optional strWindow As String)
  208.     Dim WindowClientRect As RECT
  209.     Dim use